package net.hombrecero.bigbeat.util;

import org.hibernate.HibernateException;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class HibernateAnnotationsSchemaExportUtil {

  public HibernateAnnotationsSchemaExportUtil() {
    super();
  }

  public static void main( String[] args ) {
    HibernateAnnotationsSchemaExportUtil haSchemaExportUtil = new HibernateAnnotationsSchemaExportUtil();
    haSchemaExportUtil.schemaExport();
  }

  public void schemaExport() throws HibernateException {
    //ajustamos configuracion
    AnnotationConfiguration annotationConfiguration = new AnnotationConfiguration();
    //dialecto
    annotationConfiguration.setProperty( "hibernate.dialect",
                                         "org.hibernate.dialect.HSQLDialect" );
    //annotationConfiguration.setProperty( "hibernate.dialect",
    //                                     "org.hibernate.dialect.H2Dialect" );
    //modelo de datos
    annotationConfiguration.addAnnotatedClass( net.hombrecero.bigbeat.model.Project.class  );
    annotationConfiguration.addAnnotatedClass( net.hombrecero.bigbeat.model.App.class      );
    annotationConfiguration.addAnnotatedClass( net.hombrecero.bigbeat.model.Driver.class   );
    annotationConfiguration.addAnnotatedClass( net.hombrecero.bigbeat.model.Node.class     );
    annotationConfiguration.addAnnotatedClass( net.hombrecero.bigbeat.model.User.class     );
    annotationConfiguration.addAnnotatedClass( net.hombrecero.bigbeat.model.WorkUnit.class );
    annotationConfiguration.addAnnotatedClass( net.hombrecero.bigbeat.model.Result.class   );
    annotationConfiguration.addAnnotatedClass( net.hombrecero.bigbeat.model.SubSet.class   );


    //usamos configuracion y generamos el esquema
    SchemaExport schemaExport = new SchemaExport( annotationConfiguration );
    schemaExport.setDelimiter(  ";"                   );
    schemaExport.setFormat(     true                  );
    schemaExport.setOutputFile( "bigbeat-schema.sql" );
    schemaExport.create(        true,                    /* muestra en consola */
                                false                 ); /* no lo ejecuta en la ddbb */
  }
}
